﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Expect.Core.Interfaces;

namespace Expect.Core
{
    /// <summary>
    /// Extension methods
    /// </summary>
    public static class Extensions
    {
        /// <summary>
        /// Indicate if the type is a test implementation
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public static bool IsASpecificationContainer(this Type t)
        {
            return t != null && t.GetInterfaces().Any(tInt => tInt == typeof(ISpecificationContainer)) && !t.IsAbstract;
        }

        /// <summary>
        /// Indicate if the type is a test implementation
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public static bool IsASpecificationImplementation(this Type t)
        {
            return t != null && t.GetInterfaces().Any(tInt => tInt == typeof(ISpecificationImplementation)) && !t.IsAbstract;
        }

        /// <summary>
        /// Indicate if the type is a fixture implementation
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public static bool IsAFixtureImplementation(this Type t)
        {
            return t != null && t.GetInterfaces().Any(tInt => tInt == typeof(IFixtureImplementation)) && !t.IsAbstract;
        }

        /// <summary>
        /// Indicate if the type is a fixture implementation
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public static bool IsATypeConverter(this Type t)
        {
            return t != null && t.GetInterfaces().Any(tInt => tInt == typeof(IExpectTypeConverter)) && !t.IsAbstract;
        }
    }
}
